package org.bite.lesson03;


import java.util.concurrent.TimeUnit;

public class Demo301 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            for(int i = 0; i < 500; i++){
                System.out.println("hello thread...");
                try{
                    TimeUnit.SECONDS.sleep(1);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
            }
        });
        //启动前查看线程状态
        System.out.println("启动前状态：" + thread.getState());
        System.out.println("是否存活：" + thread.isAlive());
        //启动线程
        thread.start();
        //查看状态前等待一会
        TimeUnit.MILLISECONDS.sleep(500);
        //查看启动后状态
        System.out.println("启动后状态：" + thread.getState());
        System.out.println("是否存活：" + thread.isAlive());
        //等待线程执行完成
        thread.join();
        //结束后线程状态
        System.out.println("结束后状态：" + thread.getState());
        System.out.println("是否存活：" + thread.isAlive());
    }
}
